/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package muddb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;


/**
 *
 * @author keith
 */
@Entity
@Table( name = "guild" )
@NamedQueries(
  {
    @NamedQuery( name = "Guild.findByGuildId",
                 query ="SELECT g FROM Guild g WHERE g.guildId = :guildId" ),
    @NamedQuery( name = "Guild.findByGuildName",
                 query = "SELECT g FROM Guild g WHERE g.guildName = :guildName" ),
    @NamedQuery( name = "Guild.findByGuildDescr",
                 query =  "SELECT g FROM Guild g WHERE g.guildDescr = :guildDescr" ) } )
public class Guild implements Serializable {
  private static final long serialVersionUID = 1L;
  private Integer guildId;
  private String guildName;
  private String guildDescr;
  private Collection<UserChar> userCharCollection;


  public Guild() {
  }


  public Guild( Integer guildId ) {
    this.guildId = guildId;
  }


  public Guild( String guildName ) {
    this.guildName = guildName;
  }


  public Guild( Integer guildId, String guildName ) {
    this.guildId = guildId;
    this.guildName = guildName;
  }


  @Id
  @GeneratedValue( strategy=GenerationType.SEQUENCE )
  @Column( name = "guild_id", nullable = false )
  public Integer getGuildId() {
    return guildId;
  }


  public void setGuildId( Integer guildId ) {
    this.guildId = guildId;
  }


  @Column(name = "guild_name", nullable = false, length = 20, unique = true )
  public String getGuildName() {
    return guildName;
  }


  public void setGuildName( String guildName ) {
    this.guildName = guildName;
  }


  @Column(name = "guild_descr", length = 1024)
  public String getGuildDescr() {
    return guildDescr;
  }


  public void setGuildDescr( String guildDescr ) {
    this.guildDescr = guildDescr;
  }


  @JoinTable( name = "guild_mbrshp", inverseJoinColumns =
    {
      @JoinColumn(name = "user_id", referencedColumnName = "user_id"),
      @JoinColumn(name = "char_id", referencedColumnName = "char_id")
    },
    joinColumns = {
      @JoinColumn(name = "guild_id", referencedColumnName = "guild_id")
  } )
  @ManyToMany
  public Collection<UserChar> getUserCharCollection() {
    return userCharCollection;
  }


  public void setUserCharCollection( Collection<UserChar> userCharCollection ) {
    this.userCharCollection = userCharCollection;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += ( guildId != null ? guildId.hashCode() : 0 );
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof Guild ) ) {
      return false;
    }
    Guild other = (Guild) object;
    if ( ( this.guildId == null && other.guildId != null ) || ( this.guildId != null && !this.guildId.equals( other.guildId ) ) ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "muddb.entities.Guild[guildId=" + guildId + "]";
  }

}
